<?php

namespace app\model;

use think\Model;

class SystemOperatingLog extends Model
{
    public $operating;
    public $account;
    public $startDate;
    public $endDate;

    private $data;

    public function __construct(array $data = [])
    {
        parent::__construct($data);
        $this->data = array();
    }

    public function __destruct()
    {
        parent::__destruct();
        unset(
            $this->data
        );
    }

    public function read()
    {
        return $this->order('id desc')->paginate(10);
    }

    public function getCount()
    {
        return $this->count();
    }

    public function record()
    {
        $adminUserInfo = get_admin_user_info();
        $this->data['account'] = $adminUserInfo['account'];
        $this->data['operating'] = $this->operating;
        return $this->save($this->data);
    }

    public function search()
    {
        return $this->whereTime('create_time', 'between', [$this->startDate, $this->endDate])
            ->where('account', $this->account)
            ->order('id desc')
            ->select()->toArray();
    }
}